import * as React from 'react';
import {
    IRouteComponentBaseProps,
    LOGIN_REDIRECT_KEY,
    authRely
} from '../index';

export class Login extends React.PureComponent<IRouteComponentBaseProps, any> {
    public static displayName = 'Login';

    public async componentDidMount() {
        // 保存跳转回地址
        let redirect = '/';
        const { state } = this.props.location;
        try {
            const { from } = state;
            const { pathname, search } = from;
            if (undefined !== pathname) {
                redirect = `${pathname}${search || ''}`;
            }
        } catch (err) {
            redirect = '/';
        }
        localStorage.setItem(LOGIN_REDIRECT_KEY, redirect);

        authRely.login();
    }

    public render() {
        return <div />;
    }
}
